<!DOCTYPE html>
<html lang=zh>
<head>
    <meta charset="utf-8">
    
    <title>干货：排名前16的Java工具类 | Java技术栈</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="在Java中，工具类定义了一组公共方法，这篇文章将介绍Java中使用最频繁及最通用的Java工具类。以下工具类、方法按使用流行度排名，参考数据来源于Github上随机选取的5万个开源项目源码。">
<meta name="keywords" content="Java">
<meta property="og:type" content="article">
<meta property="og:title" content="干货：排名前16的Java工具类">
<meta property="og:url" content="http://youanyyou.gitee.io/javastack/2018/02/27/Java/干货：排名前16的Java工具类/index.html">
<meta property="og:site_name" content="Java技术栈">
<meta property="og:description" content="在Java中，工具类定义了一组公共方法，这篇文章将介绍Java中使用最频繁及最通用的Java工具类。以下工具类、方法按使用流行度排名，参考数据来源于Github上随机选取的5万个开源项目源码。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-04-18T09:17:32.520Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="干货：排名前16的Java工具类">
<meta name="twitter:description" content="在Java中，工具类定义了一组公共方法，这篇文章将介绍Java中使用最频繁及最通用的Java工具类。以下工具类、方法按使用流行度排名，参考数据来源于Github上随机选取的5万个开源项目源码。">
    

    
        <link rel="alternate" href="/" title="Java技术栈" type="application/atom+xml" />
    

    

    <link rel="stylesheet" href="/javastack/libs/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/javastack/libs/open-sans/styles.css">
    <link rel="stylesheet" href="/javastack/libs/source-code-pro/styles.css">

    <link rel="stylesheet" href="/javastack/css/style.css">

    <script src="/javastack/libs/jquery/2.1.3/jquery.min.js"></script>
    
    
        <link rel="stylesheet" href="/javastack/libs/lightgallery/css/lightgallery.min.css">
    
    
        <link rel="stylesheet" href="/javastack/libs/justified-gallery/justifiedGallery.min.css">
    
    
    
    


</head>

<body>
    <div id="container">
        <header id="header">
    <div id="header-main" class="header-inner">
        <div class="outer">
            <a href="/javastack/" id="logo">
                <i class="logo"></i>
                <span class="site-title">Java技术栈</span>
            </a>
            <nav id="main-nav">
                
                    <a class="main-nav-link" href="/javastack/.">首页</a>
                
                    <a class="main-nav-link" href="/javastack/archives">归档</a>
                
                    <a class="main-nav-link" href="/javastack/categories">分类</a>
                
                    <a class="main-nav-link" href="/javastack/tags">标签</a>
                
                    <a class="main-nav-link" href="/javastack/about">关于</a>
                
            </nav>
            
                
                <nav id="sub-nav">
                    <div class="profile" id="profile-nav">
                        <a id="profile-anchor" href="javascript:;">
                            <img class="avatar" src="/javastack/css/images/avatar.jpg" />
                            <i class="fa fa-caret-down"></i>
                        </a>
                    </div>
                </nav>
            
            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="想要查找什么..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/javastack/',
        CONTENT_URL: '/javastack/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/javastack/js/insight.js"></script>

</div>
        </div>
    </div>
    <div id="main-nav-mobile" class="header-sub header-inner">
        <table class="menu outer">
            <tr>
                
                    <td><a class="main-nav-link" href="/javastack/.">首页</a></td>
                
                    <td><a class="main-nav-link" href="/javastack/archives">归档</a></td>
                
                    <td><a class="main-nav-link" href="/javastack/categories">分类</a></td>
                
                    <td><a class="main-nav-link" href="/javastack/tags">标签</a></td>
                
                    <td><a class="main-nav-link" href="/javastack/about">关于</a></td>
                
                <td>
                    
    <div class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
    </div>

                </td>
            </tr>
        </table>
    </div>
</header>

        <div class="outer">
            
                

<aside id="profile">
    <div class="inner profile-inner">
        <div class="base-info profile-block">
            <img id="avatar" src="/javastack/css/images/avatar.jpg" />
            <h2 id="name">Java技术栈</h2><br/>
            <h3 id="title">微信公众号,每日更新！</h3>
            <!--
            <span id="location">
                <i class="fa fa-map-marker"></i>Shenzhen, China
            </span>
            -->
            <a id="follow" target="_blank" href="http://youanyyou.gitee.io/javastack/css/images/avatar.jpg">扫描关注微信公众号</a>
        </div>
        <div class="article-info profile-block">
            <div class="article-info-block">
                113
                <span>文章</span>
            </div>
            <div class="article-info-block">
                58
                <span>标签</span>
            </div>
        </div>
        
        <div class="profile-block social-links">
            <table>
                <tr>
                    
                    
                    <td>
                        <a href="http://github.com/ppoffice/hexo-theme-icarus" target="_blank" title="github" class=tooltip>
                            <i class="fa fa-github"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/javastack/" target="_blank" title="twitter" class=tooltip>
                            <i class="fa fa-twitter"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/javastack/" target="_blank" title="facebook" class=tooltip>
                            <i class="fa fa-facebook"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/javastack/" target="_blank" title="dribbble" class=tooltip>
                            <i class="fa fa-dribbble"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/javastack/" target="_blank" title="rss" class=tooltip>
                            <i class="fa fa-rss"></i>
                        </a>
                    </td>
                    
                </tr>
            </table>
        </div>
        
    </div>
</aside>

            
            <section id="main"><article id="post-Java/干货：排名前16的Java工具类" class="article article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
        
            <header class="article-header">
                
    
        <h1 class="article-title" itemprop="name">
            干货：排名前16的Java工具类
        </h1>
    

                
                    <div class="article-meta">
                        
    <div class="article-date">
        <i class="fa fa-calendar"></i>
        <a href="/javastack/2018/02/27/Java/干货：排名前16的Java工具类/">
            <time datetime="2018-02-26T16:00:00.000Z" itemprop="datePublished">2018-02-27</time>
        </a>
    </div>


                        
    <div class="article-category">
    	<i class="fa fa-folder"></i>
        <a class="article-category-link" href="/javastack/categories/Java/">Java</a>
    </div>

                        
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link" href="/javastack/tags/Java/">Java</a>
    </div>

                    </div>
                
            </header>
        
        
        <div class="article-entry" itemprop="articleBody">
        
            
            <p>在Java中，工具类定义了一组公共方法，这篇文章将介绍Java中使用最频繁及最通用的Java工具类。以下工具类、方法按使用流行度排名，参考数据来源于Github上随机选取的5万个开源项目源码。</p>
<a id="more"></a>
<h4 id="一-org-apache-commons-io-IOUtils"><a href="#一-org-apache-commons-io-IOUtils" class="headerlink" title="一. org.apache.commons.io.IOUtils"></a>一. org.apache.commons.io.IOUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">closeQuietly：关闭一个IO流、socket、或者selector且不抛出异常，通常放在finally块</span><br><span class="line">toString：转换IO流、 Uri、 byte[]为String</span><br><span class="line">copy：IO流数据复制，从输入流写到输出流中，最大支持2GB</span><br><span class="line">toByteArray：从输入流、URI获取byte[]</span><br><span class="line">write：把字节. 字符等写入输出流</span><br><span class="line">toInputStream：把字符转换为输入流</span><br><span class="line">readLines：从输入流中读取多行数据，返回List&lt;String&gt;</span><br><span class="line">copyLarge：同copy，支持2GB以上数据的复制</span><br><span class="line">lineIterator：从输入流返回一个迭代器，根据参数要求读取的数据量，全部读取，如果数据不够，则失败</span><br></pre></td></tr></table></figure>
<h4 id="二-org-apache-commons-io-FileUtils"><a href="#二-org-apache-commons-io-FileUtils" class="headerlink" title="二. org.apache.commons.io.FileUtils"></a>二. org.apache.commons.io.FileUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">deleteDirectory：删除文件夹</span><br><span class="line">readFileToString：以字符形式读取文件内容</span><br><span class="line">deleteQueitly：删除文件或文件夹且不会抛出异常</span><br><span class="line">copyFile：复制文件</span><br><span class="line">writeStringToFile：把字符写到目标文件，如果文件不存在，则创建</span><br><span class="line">forceMkdir：强制创建文件夹，如果该文件夹父级目录不存在，则创建父级</span><br><span class="line">write：把字符写到指定文件中</span><br><span class="line">listFiles：列举某个目录下的文件(根据过滤器)</span><br><span class="line">copyDirectory：复制文件夹</span><br><span class="line">forceDelete：强制删除文件</span><br></pre></td></tr></table></figure>
<h4 id="三-org-apache-commons-lang-StringUtils"><a href="#三-org-apache-commons-lang-StringUtils" class="headerlink" title="三. org.apache.commons.lang.StringUtils"></a>三. org.apache.commons.lang.StringUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">isBlank：字符串是否为空 (trim后判断)</span><br><span class="line">isEmpty：字符串是否为空 (不trim并判断)</span><br><span class="line">equals：字符串是否相等</span><br><span class="line">join：合并数组为单一字符串，可传分隔符</span><br><span class="line">split：分割字符串</span><br><span class="line">EMPTY：返回空字符串</span><br><span class="line">trimToNull：trim后为空字符串则转换为null</span><br><span class="line">replace：替换字符串</span><br></pre></td></tr></table></figure>
<h4 id="四-org-apache-http-util-EntityUtils"><a href="#四-org-apache-http-util-EntityUtils" class="headerlink" title="四. org.apache.http.util.EntityUtils"></a>四. org.apache.http.util.EntityUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">toString：把Entity转换为字符串</span><br><span class="line">consume：确保Entity中的内容全部被消费。可以看到源码里又一次消费了Entity的内容，假如用户没有消费，那调用Entity时候将会把它消费掉</span><br><span class="line">toByteArray：把Entity转换为字节流</span><br><span class="line">consumeQuietly：和consume一样，但不抛异常</span><br><span class="line">getContentCharset：获取内容的编码</span><br></pre></td></tr></table></figure>
<h4 id="五-org-apache-commons-lang3-StringUtils"><a href="#五-org-apache-commons-lang3-StringUtils" class="headerlink" title="五. org.apache.commons.lang3.StringUtils"></a>五. org.apache.commons.lang3.StringUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">isBlank：字符串是否为空 (trim后判断)</span><br><span class="line">isEmpty：字符串是否为空 (不trim并判断)</span><br><span class="line">equals：字符串是否相等</span><br><span class="line">join：合并数组为单一字符串，可传分隔符</span><br><span class="line">split：分割字符串</span><br><span class="line">EMPTY：返回空字符串</span><br><span class="line">replace：替换字符串</span><br><span class="line">capitalize：首字符大写</span><br></pre></td></tr></table></figure>
<h4 id="六-org-apache-commons-io-FilenameUtils"><a href="#六-org-apache-commons-io-FilenameUtils" class="headerlink" title="六. org.apache.commons.io.FilenameUtils"></a>六. org.apache.commons.io.FilenameUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">getExtension：返回文件后缀名</span><br><span class="line">getBaseName：返回文件名，不包含后缀名</span><br><span class="line">getName：返回文件全名</span><br><span class="line">concat：按命令行风格组合文件路径(详见方法注释)</span><br><span class="line">removeExtension：删除后缀名</span><br><span class="line">normalize：使路径正常化</span><br><span class="line">wildcardMatch：匹配通配符</span><br><span class="line">seperatorToUnix：路径分隔符改成unix系统格式的，即/</span><br><span class="line">getFullPath：获取文件路径，不包括文件名</span><br><span class="line">isExtension：检查文件后缀名是不是传入参数(List&lt;String&gt;)中的一个</span><br></pre></td></tr></table></figure>
<h4 id="七-org-springframework-util-StringUtils"><a href="#七-org-springframework-util-StringUtils" class="headerlink" title="七. org.springframework.util.StringUtils"></a>七. org.springframework.util.StringUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">hasText：检查字符串中是否包含文本</span><br><span class="line">hasLength：检测字符串是否长度大于0</span><br><span class="line">isEmpty：检测字符串是否为空（若传入为对象，则判断对象是否为null）</span><br><span class="line">commaDelimitedStringToArray：逗号分隔的String转换为数组</span><br><span class="line">collectionToDelimitedString：把集合转为CSV格式字符串</span><br><span class="line">replace 替换字符串</span><br><span class="line">7. delimitedListToStringArray：相当于split</span><br><span class="line">uncapitalize：首字母小写</span><br><span class="line">collectionToDelimitedCommaString：把集合转为CSV格式字符串</span><br><span class="line">tokenizeToStringArray：和split基本一样，但能自动去掉空白的单词</span><br></pre></td></tr></table></figure>
<h4 id="八-org-apache-commons-lang-ArrayUtils"><a href="#八-org-apache-commons-lang-ArrayUtils" class="headerlink" title="八. org.apache.commons.lang.ArrayUtils"></a>八. org.apache.commons.lang.ArrayUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">contains：是否包含某字符串</span><br><span class="line">addAll：添加整个数组</span><br><span class="line">clone：克隆一个数组</span><br><span class="line">isEmpty：是否空数组</span><br><span class="line">add：向数组添加元素</span><br><span class="line">subarray：截取数组</span><br><span class="line">indexOf：查找某个元素的下标</span><br><span class="line">isEquals：比较数组是否相等</span><br><span class="line">toObject：基础类型数据数组转换为对应的Object数组</span><br></pre></td></tr></table></figure>
<h4 id="九-org-apache-commons-lang-StringEscapeUtils"><a href="#九-org-apache-commons-lang-StringEscapeUtils" class="headerlink" title="九. org.apache.commons.lang.StringEscapeUtils"></a>九. org.apache.commons.lang.StringEscapeUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">参考十五：org.apache.commons.lang3.StringEscapeUtils</span><br></pre></td></tr></table></figure>
<h4 id="十-org-apache-http-client-utils-URLEncodedUtils"><a href="#十-org-apache-http-client-utils-URLEncodedUtils" class="headerlink" title="十. org.apache.http.client.utils.URLEncodedUtils"></a>十. org.apache.http.client.utils.URLEncodedUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">format：格式化参数，返回一个HTTP POST或者HTTP PUT可用application/x-www-form-urlencoded字符串</span><br><span class="line">parse：把String或者URI等转换为List&lt;NameValuePair&gt;</span><br></pre></td></tr></table></figure>
<h4 id="十一-org-apache-commons-codec-digest-DigestUtils"><a href="#十一-org-apache-commons-codec-digest-DigestUtils" class="headerlink" title="十一. org.apache.commons.codec.digest.DigestUtils"></a>十一. org.apache.commons.codec.digest.DigestUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">md5Hex：MD5加密，返回32位字符串</span><br><span class="line">sha1Hex：SHA-1加密</span><br><span class="line">sha256Hex：SHA-256加密</span><br><span class="line">sha512Hex：SHA-512加密</span><br><span class="line">md5：MD5加密，返回16位字符串</span><br></pre></td></tr></table></figure>
<h4 id="十二-org-apache-commons-collections-CollectionUtils"><a href="#十二-org-apache-commons-collections-CollectionUtils" class="headerlink" title="十二. org.apache.commons.collections.CollectionUtils"></a>十二. org.apache.commons.collections.CollectionUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">isEmpty：是否为空</span><br><span class="line">select：根据条件筛选集合元素</span><br><span class="line">transform：根据指定方法处理集合元素，类似List的map()</span><br><span class="line">filter：过滤元素，雷瑟List的filter()</span><br><span class="line">find：基本和select一样</span><br><span class="line">collect：和transform 差不多一样，但是返回新数组</span><br><span class="line">forAllDo：调用每个元素的指定方法</span><br><span class="line">isEqualCollection：判断两个集合是否一致</span><br></pre></td></tr></table></figure>
<h4 id="十三-org-apache-commons-lang3-ArrayUtils"><a href="#十三-org-apache-commons-lang3-ArrayUtils" class="headerlink" title="十三. org.apache.commons.lang3.ArrayUtils"></a>十三. org.apache.commons.lang3.ArrayUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">contains：是否包含某个字符串</span><br><span class="line">addAll：添加整个数组</span><br><span class="line">clone：克隆一个数组</span><br><span class="line">isEmpty：是否空数组</span><br><span class="line">add：向数组添加元素</span><br><span class="line">subarray：截取数组</span><br><span class="line">indexOf：查找某个元素的下标</span><br><span class="line">isEquals：比较数组是否相等</span><br><span class="line">toObject：基础类型数据数组转换为对应的Object数组</span><br></pre></td></tr></table></figure>
<h4 id="十四-org-apache-commons-beanutils-PropertyUtils"><a href="#十四-org-apache-commons-beanutils-PropertyUtils" class="headerlink" title="十四. org.apache.commons.beanutils.PropertyUtils"></a>十四. org.apache.commons.beanutils.PropertyUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">getProperty：获取对象属性值</span><br><span class="line">setProperty：设置对象属性值</span><br><span class="line">getPropertyDiscriptor：获取属性描述器</span><br><span class="line">isReadable：检查属性是否可访问</span><br><span class="line">copyProperties：复制属性值，从一个对象到另一个对象</span><br><span class="line">getPropertyDiscriptors：获取所有属性描述器</span><br><span class="line">isWriteable：检查属性是否可写</span><br><span class="line">getPropertyType：获取对象属性类型</span><br></pre></td></tr></table></figure>
<h4 id="十五-org-apache-commons-lang3-StringEscapeUtils"><a href="#十五-org-apache-commons-lang3-StringEscapeUtils" class="headerlink" title="十五. org.apache.commons.lang3.StringEscapeUtils"></a>十五. org.apache.commons.lang3.StringEscapeUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">unescapeHtml4：转义html</span><br><span class="line">escapeHtml4：反转义html</span><br><span class="line">escapeXml：转义xml</span><br><span class="line">unescapeXml：反转义xml</span><br><span class="line">escapeJava：转义unicode编码</span><br><span class="line">escapeEcmaScript：转义EcmaScript字符</span><br><span class="line">unescapeJava：反转义unicode编码</span><br><span class="line">escapeJson：转义json字符</span><br><span class="line">escapeXml10：转义Xml10</span><br></pre></td></tr></table></figure>
<p>这个现在已经废弃了，建议使用commons-text包里面的方法。</p>
<h4 id="十六-org-apache-commons-beanutils-BeanUtils"><a href="#十六-org-apache-commons-beanutils-BeanUtils" class="headerlink" title="十六. org.apache.commons.beanutils.BeanUtils"></a>十六. org.apache.commons.beanutils.BeanUtils</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">copyPeoperties：复制属性值，从一个对象到另一个对象</span><br><span class="line">getProperty：获取对象属性值</span><br><span class="line">setProperty：设置对象属性值</span><br><span class="line">populate：根据Map给属性复制</span><br><span class="line">copyPeoperty：复制单个值，从一个对象到另一个对象</span><br><span class="line">cloneBean：克隆bean实例</span><br></pre></td></tr></table></figure>
<p>现在你只要了解了以上16种最流行的工具类方法，你就不必要再自己写工具类了，不必重复造轮子。大部分工具类方法通过其名字就能明白其用途，如果不清楚的，可以看下别人是怎么用的，或者去网上查询其用法。</p>
<p>另外，工具类，根据阿里开发手册，包名如果要使用util不能带s，工具类命名为<code>XxxUtils</code>。</p>

        
        </div>
        <footer class="article-footer">
            <div class="share-container">



</div>

    <a data-url="http://youanyyou.gitee.io/javastack/2018/02/27/Java/干货：排名前16的Java工具类/" data-id="cjg4zd8mo0026hg8a3k9tlqrd" class="article-share-link"><i class="fa fa-share"></i>分享到</a>
<script>
    (function ($) {
        // Prevent duplicate binding
        if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
            __SHARE_BUTTON_BINDED__ = true;
        } else {
            return;
        }
        $('body').on('click', function() {
            $('.article-share-box.on').removeClass('on');
        }).on('click', '.article-share-link', function(e) {
            e.stopPropagation();

            var $this = $(this),
                url = $this.attr('data-url'),
                encodedUrl = encodeURIComponent(url),
                id = 'article-share-box-' + $this.attr('data-id'),
                offset = $this.offset(),
                box;

            if ($('#' + id).length) {
                box = $('#' + id);

                if (box.hasClass('on')){
                    box.removeClass('on');
                    return;
                }
            } else {
                var html = [
                    '<div id="' + id + '" class="article-share-box">',
                        '<input class="article-share-input" value="' + url + '">',
                        '<div class="article-share-links">',
                            '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
                            '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
                            '<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
                            '<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
                        '</div>',
                    '</div>'
                ].join('');

              box = $(html);

              $('body').append(box);
            }

            $('.article-share-box.on').hide();

            box.css({
                top: offset.top + 25,
                left: offset.left
            }).addClass('on');

        }).on('click', '.article-share-box', function (e) {
            e.stopPropagation();
        }).on('click', '.article-share-box-input', function () {
            $(this).select();
        }).on('click', '.article-share-box-link', function (e) {
            e.preventDefault();
            e.stopPropagation();

            window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
        });
    })(jQuery);
</script>

            
    

        </footer>
    </div>
    
        
<nav id="article-nav">
    
        <a href="/javastack/2018/03/04/Java/JDK9/JDK9新特性实战：简化流关闭新姿势。/" id="article-nav-newer" class="article-nav-link-wrap">
            <strong class="article-nav-caption">上一篇</strong>
            <div class="article-nav-title">
                
                    JDK9新特性实战：简化流关闭新姿势。
                
            </div>
        </a>
    
    
        <a href="/javastack/2018/02/27/tomcat/注意：Tomcat Get请求的坑！/" id="article-nav-older" class="article-nav-link-wrap">
            <strong class="article-nav-caption">下一篇</strong>
            <div class="article-nav-title">注意：Tomcat Get请求的坑！</div>
        </a>
    
</nav>


    
</article>


    
    

</section>
            
                
<aside id="sidebar">
   
        
    <div class="widget-wrap">
        <h3 class="widget-title">分类</h3>
        <div class="widget">
            <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/Java/">Java</a><span class="category-list-count">37</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/Java/多线程/">多线程</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/Java/新特性/">新特性</a><span class="category-list-count">10</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/Maven/">Maven</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/Mybatis/">Mybatis</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/Netty/">Netty</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/Tomcat/">Tomcat</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/书籍推荐/">书籍推荐</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/云计算/">云计算</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/开源项目/">开源项目</a><span class="category-list-count">10</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/测试/">测试</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/漏洞/">漏洞</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/程序人生/">程序人生</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/算法/">算法</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/编程语言/">编程语言</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/行业动态/">行业动态</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/javastack/categories/连接池/">连接池</a><span class="category-list-count">2</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">技术栈</h3>
        <div class="widget tagcloud">
            <a href="/javastack/tags/CAT/" style="font-size: 10px;">CAT</a> <a href="/javastack/tags/Cobar/" style="font-size: 10px;">Cobar</a> <a href="/javastack/tags/Cookie/" style="font-size: 10px;">Cookie</a> <a href="/javastack/tags/Disconf/" style="font-size: 10px;">Disconf</a> <a href="/javastack/tags/Druid/" style="font-size: 12.86px;">Druid</a> <a href="/javastack/tags/Eclipse/" style="font-size: 10px;">Eclipse</a> <a href="/javastack/tags/Facebook/" style="font-size: 10px;">Facebook</a> <a href="/javastack/tags/IP/" style="font-size: 10px;">IP</a> <a href="/javastack/tags/IaaS/" style="font-size: 10px;">IaaS</a> <a href="/javastack/tags/JVM/" style="font-size: 10px;">JVM</a> <a href="/javastack/tags/Java/" style="font-size: 20px;">Java</a> <a href="/javastack/tags/Jodd/" style="font-size: 10px;">Jodd</a> <a href="/javastack/tags/Junit/" style="font-size: 10px;">Junit</a> <a href="/javastack/tags/Kotlin/" style="font-size: 10px;">Kotlin</a> <a href="/javastack/tags/LVS/" style="font-size: 10px;">LVS</a> <a href="/javastack/tags/Maven/" style="font-size: 14.29px;">Maven</a> <a href="/javastack/tags/Mybatis/" style="font-size: 10px;">Mybatis</a> <a href="/javastack/tags/NIO/" style="font-size: 10px;">NIO</a> <a href="/javastack/tags/Netty/" style="font-size: 10px;">Netty</a> <a href="/javastack/tags/Nginx/" style="font-size: 10px;">Nginx</a> <a href="/javastack/tags/Oracle/" style="font-size: 11.43px;">Oracle</a> <a href="/javastack/tags/PaaS/" style="font-size: 10px;">PaaS</a> <a href="/javastack/tags/Python/" style="font-size: 10px;">Python</a> <a href="/javastack/tags/SaaS/" style="font-size: 10px;">SaaS</a> <a href="/javastack/tags/Squid/" style="font-size: 10px;">Squid</a> <a href="/javastack/tags/Tengine/" style="font-size: 10px;">Tengine</a> <a href="/javastack/tags/Thrift/" style="font-size: 10px;">Thrift</a> <a href="/javastack/tags/Tomcat/" style="font-size: 12.86px;">Tomcat</a> <a href="/javastack/tags/https/" style="font-size: 10px;">https</a> <a href="/javastack/tags/jdk10/" style="font-size: 10px;">jdk10</a> <a href="/javastack/tags/jdk7/" style="font-size: 10px;">jdk7</a> <a href="/javastack/tags/jdk8/" style="font-size: 17.14px;">jdk8</a> <a href="/javastack/tags/jdk9/" style="font-size: 10px;">jdk9</a> <a href="/javastack/tags/书籍/" style="font-size: 15.71px;">书籍</a> <a href="/javastack/tags/云计算/" style="font-size: 10px;">云计算</a> <a href="/javastack/tags/代理/" style="font-size: 10px;">代理</a> <a href="/javastack/tags/分布式/" style="font-size: 11.43px;">分布式</a> <a href="/javastack/tags/区块链/" style="font-size: 10px;">区块链</a> <a href="/javastack/tags/多线程/" style="font-size: 12.86px;">多线程</a> <a href="/javastack/tags/安全/" style="font-size: 10px;">安全</a> <a href="/javastack/tags/开源项目/" style="font-size: 18.57px;">开源项目</a> <a href="/javastack/tags/性能优化/" style="font-size: 10px;">性能优化</a> <a href="/javastack/tags/攻击/" style="font-size: 10px;">攻击</a> <a href="/javastack/tags/数据库/" style="font-size: 10px;">数据库</a> <a href="/javastack/tags/架构师/" style="font-size: 11.43px;">架构师</a> <a href="/javastack/tags/测试/" style="font-size: 10px;">测试</a> <a href="/javastack/tags/漏洞/" style="font-size: 11.43px;">漏洞</a> <a href="/javastack/tags/监控/" style="font-size: 11.43px;">监控</a> <a href="/javastack/tags/程序人生/" style="font-size: 12.86px;">程序人生</a> <a href="/javastack/tags/算法/" style="font-size: 11.43px;">算法</a> <a href="/javastack/tags/缓存/" style="font-size: 10px;">缓存</a> <a href="/javastack/tags/编程语言/" style="font-size: 10px;">编程语言</a> <a href="/javastack/tags/腾讯/" style="font-size: 10px;">腾讯</a> <a href="/javastack/tags/行业动态/" style="font-size: 10px;">行业动态</a> <a href="/javastack/tags/负载均衡/" style="font-size: 11.43px;">负载均衡</a> <a href="/javastack/tags/连接池/" style="font-size: 12.86px;">连接池</a> <a href="/javastack/tags/阿里巴巴/" style="font-size: 14.29px;">阿里巴巴</a> <a href="/javastack/tags/高并发/" style="font-size: 10px;">高并发</a>
        </div>
    </div>

    
        
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">链接</h3>
        <div class="widget">
            <ul>
                
                    <li>
                        <a href="http://hexo.io">Hexo</a>
                    </li>
                
            </ul>
        </div>
    </div>


    
    <div id="toTop" class="fa fa-angle-up"></div>
</aside>

            
        </div>
        <footer id="footer">
    <div class="outer">
        <div id="footer-info" class="inner">
            &copy; 2018 Java技术栈 版权所有
            <br>
            Powered by <a href="http://www.javastack.cn/" target="_self">javastack.cn</a>. 
        </div>
    </div>
</footer>
        


    
        <script src="/javastack/libs/lightgallery/js/lightgallery.min.js"></script>
        <script src="/javastack/libs/lightgallery/js/lg-thumbnail.min.js"></script>
        <script src="/javastack/libs/lightgallery/js/lg-pager.min.js"></script>
        <script src="/javastack/libs/lightgallery/js/lg-autoplay.min.js"></script>
        <script src="/javastack/libs/lightgallery/js/lg-fullscreen.min.js"></script>
        <script src="/javastack/libs/lightgallery/js/lg-zoom.min.js"></script>
        <script src="/javastack/libs/lightgallery/js/lg-hash.min.js"></script>
        <script src="/javastack/libs/lightgallery/js/lg-share.min.js"></script>
        <script src="/javastack/libs/lightgallery/js/lg-video.min.js"></script>
    
    
        <script src="/javastack/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>
    
    



<!-- Custom Scripts -->
<script src="/javastack/js/main.js"></script>

    </div>
</body>
</html>